define(["require", "exports", "./GlobalClass"], function (require, exports, GlobalClass_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**通用方法类 */
    class CommonFunction {
        static ins() {
            if (CommonFunction.self != null) {
                return CommonFunction.self;
            }
            else {
                return new CommonFunction();
            }
        }
        constructor() {
            CommonFunction.self = this;
        }
        /**根据id获取HTML元素
         * @param id_name 元素id名称
        */
        IdToElement(id_name) {
            let temp_ele = document.getElementById(id_name);
            return temp_ele;
        }
        /**使元素居中[margin]
         * @param elem 要居中的元素
         * @param refer 居中参照的宽高
         * @param dire 居中的方向 H:横向居中 V:纵向居中 HV:横向纵向都居中
        */
        CenterElement(elem, refer, dire) {
            let H_Interval = 0;
            let V_Interval = 0;
            let elem_width = parseInt(elem.style.width.replace(" px", ""));
            let elem_height = parseInt(elem.style.height.replace(" px", ""));
            if (isNaN(elem_width) && dire == "H") {
                return;
            }
            else if (isNaN(elem_height) && dire == "V") {
                return;
            }
            else if (isNaN(elem_width) || isNaN(elem_height)) {
                return;
            }
            H_Interval = (refer.width - elem_width) / 2;
            V_Interval = (refer.height - elem_height) / 2;
            switch (dire) {
                case "H":
                    elem.style.marginLeft = H_Interval + "px";
                    elem.style.marginRight = H_Interval + "px";
                    break;
                case "V":
                    elem.style.marginTop = V_Interval + "px";
                    elem.style.marginBottom = V_Interval + "px";
                    break;
                case "HV":
                    elem.style.marginLeft = H_Interval + "px";
                    elem.style.marginRight = H_Interval + "px";
                    elem.style.marginTop = V_Interval + "px";
                    elem.style.marginBottom = V_Interval + "px";
                    break;
            }
        }
        /**两点之间的距离 */
        InstanceToPoints(A, B) {
            let ins = 0;
            let double_x = (A.x - B.x) * (A.x - B.x);
            let double_y = (A.y - B.y) * (A.y - B.y);
            ins = Math.abs(Math.sqrt(double_x + double_y));
            return parseInt(ins.toFixed(0));
        }
        /**往对象内添加新属性
         * @param add_obj 要添加的对象
         * @param map_atts 要添加的属性类型与值,以map类型的数组形式
        */
        AddObjectAttribute(add_obj, map_atts) {
            if (typeof add_obj == "object") {
                for (let i = 0; i < map_atts.length; i++) {
                    let temp_map = map_atts[i];
                    temp_map.forEach((value, key) => {
                        add_obj[key] = value;
                    });
                }
            }
        }
        /**多种标签监听同类型的事件
         * @param elems 要监听的元素数组
         * @param event 要监听的事件
         * @param callback 监听回调
        */
        ListenerTypeEvents(elems, event, callback) {
            let temp = null;
            if (elems.length != 0) {
                for (let i = 0; i < elems.length; i++) {
                    temp = elems[i];
                    GlobalClass_1.GlobalClass.ListenerCenter.addEvent(event, temp, callback);
                }
            }
        }
    }
    exports.CommonFunction = CommonFunction;
});
